#define _CRT_SECURE_NO_WARNINGS
#include<string>
#include<iostream>
using namespace std;
string addStrings(string num1, string num2) {
    if (num1.size() > num2.size())
    {
        num2.insert(0, num1.size() - num2.size(), '0');
    }
    else
    {
        num1.insert(0, num2.size() - num1.size(), '0');
    }
    size_t i = num1.size() - 1;
    int carry = 0;
    int add = 0;
    string sum;
    while ((int)i >= 0)
    {
        add = num1[i] + num2[i] - 2 * '0' + carry;
        if (add > 9)
        {
            carry = add / 10;
            add %= 10;
            sum.insert(0, 1, add + '0');
        }
        else
        {
            sum.insert(0, 1, add + '0');
            carry = 0;
        }
        i--;
    }
    if (carry > 0)
    {
        sum.insert(0, 1, '0' + carry);
    }
    return sum;

    /*string addStrings(string num1, string num2) {
        int i=num1.size()-1;
        int j=num2.size()-1;
        int carry=0;
        string sum;
        while(i>=0||j>=0)
        {
            int x=i<0?0:num1[i--]-'0';
            int y=j<0?0:num2[j--]-'0';
            int result=x+y+carry;
            carry=result/10;
            if(result>9)
            {
                result%=10;
            }
            sum+='0'+result;
        }
        if(carry>0)
        {
            sum+='0'+carry;
        }
        reverse(sum.begin(),sum.end());
        return sum;*/
}
int main()
{
	string S1("456");
	string S2("77");
    string S3 = addStrings(S1, S2);
    cout << S3 << endl;
	return 0;
}